package com.rc.evcharger.common.type;

import java.lang.reflect.Field;
import java.util.Date;

/**
 * 实时对象数据格式（实时写对象）
 * @author kb
 */
public class RealObjData extends BaseType implements DataType {
    String measuringPoint; // 测量点号
    String permisson; // 权限等级
    String password; // 密码
    String year;     //年
    String month;   //月
    String day;     //日
    String hour;    //小时
    String min;     //分
    String validTime;  //有效时间默认为10分钟
    String[] code;    //数据项编号
    String[] value;   //数据项内容

    public RealObjData() {
        super();
    }

    public RealObjData(String measuringPoint, String permisson, String password, Date date, String vaildTime, String[] code, String[] value) {
        super();
        this.year = String.valueOf(date.getYear());
        this.year = this.year.substring(2);
        this.month = String.valueOf(date.getMonth());
        if (month.length() < 2) {
            this.month = "0" + this.month;
        }
        this.hour = String.valueOf(date.getHours());
        if (this.hour.length() < 2) {
            this.hour = "0" + this.hour;
        }
        this.min = String.valueOf(date.getMinutes());
        if (this.min.length() < 2) {
            this.min = "0" + this.min;
        }
        if (validTime == null)
            validTime = "10";//默认为10分钟
        this.validTime = (validTime.length() < 2 ? "0" + vaildTime : vaildTime);
        this.measuringPoint = measuringPoint;
        this.permisson = permisson;
        this.password = password;
        this.code = code;
        this.value = value;
    }


    public String getMeasuringPoint() {
        return measuringPoint;
    }


    public void setMeasuringPoint(String measuringPoint) {
        this.measuringPoint = measuringPoint;
    }


    public String getPermisson() {
        return permisson;
    }


    public void setPermisson(String permisson) {
        this.permisson = permisson;
    }


    public String getPassword() {
        return password;
    }


    public void setPassword(String password) {
        this.password = password;
    }


    public String getYear() {
        return year;
    }


    public void setYear(String year) {
        this.year = year;
    }


    public String getMonth() {
        return month;
    }


    public void setMonth(String month) {
        this.month = month;
    }


    public String getDay() {
        return day;
    }


    public void setDay(String day) {
        this.day = day;
    }


    public String getMin() {
        return min;
    }


    public void setMin(String min) {
        this.min = min;
    }


    public String getValidTime() {
        return validTime;
    }


    public void setValidTime(String validTime) {
        this.validTime = validTime;
    }


    public String[] getCode() {
        return code;
    }


    public void setCode(String[] code) {
        this.code = code;
    }


    public String[] getValue() {
        return value;
    }


    public void setValue(String[] value) {
        this.value = value;
    }

    @Override
    public boolean customField(Field field, StringBuffer sb) {
        if (field.getName().equals("code")) {
            return true;
        }
        if (field.getName().equals("code")) {
            for (int i = 0; i < code.length; i++) {
                sb.append(code[i]).append(SPLIT)
                        .append(value[i]).append(SPLIT);
            }
            return true;
        }
        return false;
    }


}
